package com.woniuxy.session.controller;

import com.woniuxy.session.entity.Goods;
import com.woniuxy.session.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: linKe
 * @Date: 2022/1/6 16:50
 * @FileName: GoodsController
 * @version: 1.0
 * @Description: 商品服务控制器
 */
@RestController
@RequestMapping("/mall")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("/{id}")
    public Goods getGoods(@PathVariable int id){
        return  goodsService.getById(id);
    }

    @GetMapping("/buy/{id}")
    public Goods updateGoods(@PathVariable int id){
        return goodsService.updateGoods(id);
    }

    @GetMapping("/init")
    public String init(){
       goodsService.init(50);
       return "ok";
    }
    @GetMapping("/buy/{goodsId}/{userId}")
    public String buy(@PathVariable() int goodsId,@PathVariable() int userId){
        goodsService.buy(goodsId,userId);
        return "ok";
    }
}
